package com.shopping.dao;

import com.shopping.pojo.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface ShoppingCartDao {
    String TABLE_NAME = "shopping_cart";
    String INSERT_FIELDS = "user_id userId, trade_id tradeId, store_id storeId, number";
    String SELECT_FIELDS = "id, user_id userId, trade_id readeId, store_id storeId, number";

    @Insert({"insert into ", TABLE_NAME, "(",INSERT_FIELDS,")", "values(#{userId}, #{tradeId}, #{storeId}, #{number})"})
    int insert(ShoppingCart shoppingCart);

    @Delete({"delete from ", TABLE_NAME, " where id = #{id}"})
    int delete(@Param("id") Integer id);

    @Update({"update ", TABLE_NAME, "set user_id = #{userId}, trade_id = #{tradeId}, store_id = #{storeId}, number = #{number}"})
    int update(ShoppingCart shoppingCart);

    @Select({"select ",SELECT_FIELDS, "from ", TABLE_NAME, "where user_id = #{userId}"})
    List<ShoppingCart> selectByUserId(Integer userId);


}
